package com.ciwong.epaper.modules.epaper.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseExpandableListAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.TextView;

import com.ciwong.epaper.R;
import com.ciwong.epaper.modules.evaluate.ui.PhoneticSymbolActivity;
import com.ciwong.epaper.modules.msg.bean.Symbols;
import com.ciwong.epaper.modules.msg.bean.SymbolsContent;
import com.ciwong.epaper.modules.viedoexplantion.util.ViedoJumpManager;

import java.util.List;

public class SymbolExpandableListAdapter extends BaseExpandableListAdapter {
    private Context mContext;
    private List<SymbolsContent> symbolsContents;
    private GridView gridView;

    public SymbolExpandableListAdapter(List<SymbolsContent> symbolsContents,Context mContext){
        this.mContext = mContext;
        this.symbolsContents = symbolsContents;
    }

    @Override
    public int getGroupCount() {
        return symbolsContents.size();
    }

    @Override
    public int getChildrenCount(int i) {
        return 1;
    }

    @Override
    public Object getGroup(int i) {
        return symbolsContents.get(i);
    }

    @Override
    public Object getChild(int i, int i1) {
        return symbolsContents.get(i).getSymbolsList().get(i1);
    }

    @Override
    public long getGroupId(int i) {
        return i;
    }

    @Override
    public long getChildId(int i, int i1) {
        return i1;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) {
        ViewHolderGroup groupHolder;
        if(view == null){
            view = LayoutInflater.from(mContext).inflate(R.layout.activity_symbol_parent,viewGroup,false);
            groupHolder = new ViewHolderGroup();
            groupHolder.symbol_group_name = (TextView) view.findViewById(R.id.symbol_text_parent);
            view.setTag(groupHolder);
        }else {
            groupHolder = (ViewHolderGroup) view.getTag();
        }
        groupHolder.symbol_group_name.setText(symbolsContents.get(i).getName());
        return view;
    }

    @Override
    public View getChildView(final int i, final int i1, boolean b, View view, ViewGroup viewGroup) {
        ViewHolderItem viewHolderItem;
        if(null == view) {
            view = LayoutInflater.from(mContext).inflate(R.layout.activity_symbol_grid, viewGroup, false);
        }
        gridView = (GridView) view;
        SymbolGridViewAdapter symbolGridViewAdapter = new SymbolGridViewAdapter(symbolsContents.get(i).getSymbolsList(),mContext);
        gridView.setAdapter(symbolGridViewAdapter);

        /*gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Symbols symbols = symbolsContents.get(i).getSymbolsList().get(i1);
                ViedoJumpManager.jumpToSymbolVideo(R.string.go_back, (Activity) mContext,symbols);
            }
        });*/

            /*viewHolderItem = new ViewHolderItem();
            viewHolderItem.symbol_btn = (Button) view.findViewById(R.id.symbol_btn_child);
            view.setTag(viewHolderItem);
            viewHolderItem =(ViewHolderItem) view.getTag();
        viewHolderItem.symbol_btn.setText("["+symbolsContents.get(i).getSymbolsList().get(i1).getSymbols()+"]");*/
        return view;
    }

    @Override
    public boolean isChildSelectable(int i, int i1) {
        return true;
    }


    private static class ViewHolderGroup{
        private TextView symbol_group_name;
    }

    private static class ViewHolderItem{
        private Button symbol_btn;
    }
}
